home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / sys / amiga / src / pla_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-23  |  8.6 KB  |  376 lines

  1. /* $Id: pla_menu.c,v 1.5 1994/08/23 16:39:00 mjl Exp $
  2.  * $Log: pla_menu.c,v $
  3.  * Revision 1.5  1994/08/23  16:39:00  mjl
  4.  * Minor fixes to work with PLplot 4.99h distribution and other cleaning up.
  5.  *
  6.  * Revision 1.4  1994/05/23  22:11:57  mjl
  7.  * Minor incompatibilities with main sources fixed.
  8.  *
  9.  * Revision 1.3  1994/03/23  08:57:43  mjl
  10.  * Header file rearrangement.  Broke code for saving an iff file from the
  11.  * current screen off into plamiga_saveiff().
  12. */
  13.  
  14. /*    pla_menu.c
  15.  
  16.     Functions for handling Amiga menu selections and other IDCMP events.
  17. */
  18.  
  19. #include "plplotP.h"
  20. #include "drivers.h"
  21. #include "plamiga.h"
  22. #include "plevent.h"
  23. #include <ctype.h>
  24.  
  25. int saveiff(char *);
  26.  
  27. /*----------------------------------------------------------------------*\
  28.  * plamiga_Open()
  29.  *
  30.  * For opening a file.  User must enable by setting an open-file handler.
  31.  * See plrender.c for more detail.
  32. \*----------------------------------------------------------------------*/
  33.  
  34. int
  35. plamiga_Open(void)
  36. {
  37.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  38.     return(1);
  39. }
  40.  
  41. /*----------------------------------------------------------------------*\
  42.  * plamiga_Save()
  43.  *
  44.  * Save to existing file.
  45. \*----------------------------------------------------------------------*/
  46.  
  47. int
  48. plamiga_Save(void)
  49. {
  50.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  51.     return(1);
  52. }
  53.  
  54. /*----------------------------------------------------------------------*\
  55.  * plamiga_SaveAs_ILBM()
  56.  *
  57.  * Screen dump.  
  58. \*----------------------------------------------------------------------*/
  59.  
  60. int
  61. plamiga_SaveAs_ILBM(void)
  62. {
  63.     struct rtFileRequester *filereq;
  64.     char filename[34];
  65.     int status;
  66.  
  67.     if (filereq = rtAllocRequestA (RT_FILEREQ, NULL)) {
  68.     filename[0] = 0;
  69.     if (rtFileRequest (filereq, filename, "Enter IFF file name",
  70.                RT_LockWindow, 1, RTFI_Flags, FREQF_PATGAD,
  71.                TAG_END)) {
  72.  
  73.         if (plamiga_saveiff(filename))
  74.         rtEZRequest ("Unable to save bitmap.\n", "OK", NULL, NULL);
  75.     }
  76.     }
  77.  
  78.     return(1);
  79. }
  80.  
  81. /*----------------------------------------------------------------------*\
  82.  * plamiga_saveiff()
  83.  *
  84.  * Screen dump work routine.
  85. \*----------------------------------------------------------------------*/
  86.  
  87. int
  88. plamiga_saveiff(char *filename)
  89. {
  90.     APTR windowlock;
  91.     int status;
  92.  
  93.     windowlock = rtLockWindow(pla->window);
  94.     status = saveiff(filename);
  95.     rtUnlockWindow(pla->window, windowlock);
  96.  
  97.     return(status);
  98. }
  99.  
  100. /*----------------------------------------------------------------------*\
  101.  * plamiga_Print_Bitmap()
  102.  *
  103.  * Self-explanatory.
  104. \*----------------------------------------------------------------------*/
  105.  
  106. int
  107. plamiga_Print_Bitmap(void)
  108. {
  109.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  110.     return(1);
  111. }
  112.  
  113. /*----------------------------------------------------------------------*\
  114.  * plamiga_Print_landscape()
  115.  *
  116.  * Self-explanatory.
  117. \*----------------------------------------------------------------------*/
  118.  
  119. int
  120. plamiga_Print_landscape(void)
  121. {
  122.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  123.     return(1);
  124. }
  125.  
  126. /*----------------------------------------------------------------------*\
  127.  * plamiga_Print_portrait()
  128.  *
  129.  * Self-explanatory.
  130. \*----------------------------------------------------------------------*/
  131.  
  132. int
  133. plamiga_Print_portrait(void)
  134. {
  135.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  136.     return(1);
  137. }
  138.  
  139. /*----------------------------------------------------------------------*\
  140.  * plamiga_About()
  141.  *
  142.  * Self-explanatory.
  143. \*----------------------------------------------------------------------*/
  144.  
  145. int
  146. plamiga_About(void)
  147. {
  148.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  149.     return(1);
  150. }
  151.  
  152. /*----------------------------------------------------------------------*\
  153.  * plamiga_Quit()
  154.  *
  155.  * Self-explanatory.
  156. \*----------------------------------------------------------------------*/
  157.  
  158. int
  159. plamiga_Quit(void)
  160. {
  161.     plspause(0);
  162.     plexit("");
  163.     return(0);
  164. }
  165.  
  166. /*----------------------------------------------------------------------*\
  167.  * plamiga_Screenmode()
  168.  *
  169.  * Brings up ReqTools Screenmode requester.
  170. \*----------------------------------------------------------------------*/
  171.  
  172. int
  173. plamiga_Screenmode(void)
  174. {
  175.     struct rtScreenModeRequester *scrmodereq;
  176.  
  177.     if (scrmodereq = rtAllocRequestA (RT_SCREENMODEREQ, NULL)) {
  178.  
  179.     if (rtScreenModeRequest (scrmodereq, "Pick a screen mode:",
  180.                  RT_LockWindow, 1, RTSC_Flags,
  181.                  SCREQF_DEPTHGAD | SCREQF_SIZEGADS |
  182.                  SCREQF_OVERSCANGAD,
  183.                  TAG_END)) {
  184.  
  185.         pla->scr_width    = scrmodereq->DisplayWidth;
  186.         pla->scr_height    = scrmodereq->DisplayHeight;
  187.  
  188.         pla->scr_depth    = scrmodereq->DisplayDepth;
  189.         pla->maxcolors    = pow(2., (double) pla->scr_depth);
  190.  
  191.         pla->scr_displayID    = scrmodereq->DisplayID;
  192.  
  193. /* Close and reopen screen, window. */
  194.  
  195.         pla->restart = 1;
  196.         pla_CloseWindow();
  197.         pla_CloseScreen();
  198.         pla_SetFont();
  199.         pla_InitDisplay();
  200.  
  201. /* Set up plotting scale factors */
  202.  
  203.         pla->xscale = (double) pla->cur_width / pla->init_width;
  204.         pla->yscale = (double) pla->cur_height / pla->init_height;
  205.  
  206. /* Redraw the plot */
  207.  
  208.         plRemakePlot(plsc);
  209.     }
  210.     rtFreeRequest (scrmodereq);
  211.     }
  212.     else
  213.     rtEZRequest ("Out of memory!", "Oh boy!", NULL, NULL);
  214.  
  215.     return(1);
  216. }
  217.  
  218. /*----------------------------------------------------------------------*\
  219.  * plamiga_Palette0()
  220.  *
  221.  * Brings up ReqTools palette requester for setting cmap0.
  222. \*----------------------------------------------------------------------*/
  223.  
  224. int
  225. plamiga_Palette0(void)
  226. {
  227.     (void) rtPaletteRequest ("Change Color Map", NULL, RT_LockWindow, 1,
  228.                  TAG_END); 
  229.  
  230.     return(1);
  231. }
  232.  
  233. /*----------------------------------------------------------------------*\
  234.  * plamiga_Palette1()
  235.  *
  236.  * Currently unimplemented.
  237. \*----------------------------------------------------------------------*/
  238.  
  239. int
  240. plamiga_Palette1(void)
  241. {
  242.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  243.     return(1);
  244. }
  245.  
  246. /*----------------------------------------------------------------------*\
  247.  * plamiga_LoadConfig()
  248.  *
  249.  * Load configuration.
  250. \*----------------------------------------------------------------------*/
  251.  
  252. int
  253. plamiga_LoadConfig(void)
  254. {
  255.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  256.     return(1);
  257. }
  258.  
  259. /*----------------------------------------------------------------------*\
  260.  * plamiga_SaveConfigAs()
  261.  *
  262.  * Save configuration to specified file.
  263. \*----------------------------------------------------------------------*/
  264.  
  265. int
  266. plamiga_SaveConfigAs(void)
  267. {
  268.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  269.     return(1);
  270. }
  271.  
  272. /*----------------------------------------------------------------------*\
  273.  * plamiga_SaveConfig()
  274.  *
  275.  * Save configuration.
  276. \*----------------------------------------------------------------------*/
  277.  
  278. int
  279. plamiga_SaveConfig(void)
  280. {
  281.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  282.     return(1);
  283. }
  284.  
  285. /*----------------------------------------------------------------------*\
  286.  * plamiga_DUMMY()
  287.  *
  288.  * User menus to go here.
  289. \*----------------------------------------------------------------------*/
  290.  
  291. int
  292. plamiga_DUMMY(void)
  293. {
  294.     rtEZRequest ("Option currently unimplemented.\n", "OK", NULL, NULL);
  295.     return(1);
  296. }
  297.  
  298. /*----------------------------------------------------------------------*\
  299.  * plamiga_KEY()
  300.  *
  301.  * Keypress handler.
  302. \*----------------------------------------------------------------------*/
  303.  
  304. int
  305. plamiga_KEY(void)
  306. {
  307.     PLKey key;
  308.     int input_char;
  309.  
  310. /* Defaults */
  311.  
  312.     input_char = PlplotMsg.Code;
  313.     key.code = 0;
  314.     key.string[0] = '\0';
  315.  
  316. /* Translate keystroke into a PLKey */
  317.  
  318.     if (isprint(input_char)) {
  319.     key.string[0] = input_char;
  320.     key.string[1] = '\0';
  321.     }
  322.     else {
  323.     switch (input_char) {
  324.     case 0x08:
  325.         key.code = PLK_BackSpace;
  326.         break;
  327.  
  328.     case 0x09:
  329.         key.code = PLK_Tab;
  330.         break;
  331.  
  332.     case 0x0A:
  333.         key.code = PLK_Linefeed;
  334.         break;
  335.  
  336.     case 0x0D:
  337.         key.code = PLK_Return;
  338.         break;
  339.  
  340.     case 0x1B:
  341.         key.code = PLK_Escape;
  342.         break;
  343.  
  344.     case 0xFF:
  345.         key.code = PLK_Delete;
  346.         break;
  347.     }
  348.     }
  349.  
  350. #ifdef DEBUG
  351.     printf("Keycode %x, string: %s\n", key.code, key.string);
  352. #endif
  353.  
  354. /* Call user event handler */
  355. /* Since this is called first, the user can disable all plplot internal
  356.    event handling by setting key.code to 0 and key.string to '\0' */
  357.  
  358.     if (plsc->KeyEH != NULL)
  359.     (*plsc->KeyEH) (&key, NULL, &pla->exit_eventloop);
  360.  
  361. /* Handle internal events */
  362.  
  363. /* Advance to next page (i.e. terminate event loop) on a <eol> */
  364.  
  365.     if (key.code == PLK_Linefeed || key.code == PLK_Return)
  366.     pla->exit_eventloop = TRUE;
  367.  
  368. /* Terminate on a 'Q' (not 'q', since it's too easy to hit by mistake) */
  369.  
  370.     if (key.string[0] == 'Q') {
  371.     plspause(0);
  372.     plexit("");
  373.     }
  374.     return(!pla->exit_eventloop);
  375. }
  376.